'use strict'
$('#lg').click(function() {
    let username = $('#username').val();
    let pwd = $('#pwd').val();
    if (username.length > 0 && pwd.length > 0) {
        $.ajax({
            url: "/loginDone",
            type: "post",
            data: {
                username: username,
                pwd: pwd
            },
            dataType: "json",
            success: function(res) {
                if (res.code === 200) {
                    window.location.href = '/individual'
                } else {
                    alter_fn(res.msg);
                }
            },
            error: function(msg) {
                alter_fn('There is a problem with the network or server')
            }
        })
    } else {
        alter_fn('Account or password cannot be empty')
        return false;
    }
});


$('#re').click(function() {
    window.location.href = '/register'
});


function alter_fn(msg) {
    $('#msg').text(msg);
    $('.invisible').removeClass('invisible');
    setTimeout(() => {
        $('.alert').addClass('invisible');
    }, 3000);
}